package Test;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class Pokers {
    public static final String[] STUITS = {"♥","♠","♣","♦"};


    public static List<Pocker>buyPocks(){
        List<Pocker> pockerList = new ArrayList<Pocker>();

        for (int i = 0; i < 4; i++) {   //花色
            for (int j = 1; j < 13; j++) {  //面值
                String suit = STUITS[i]; //花色
                //int rank = j; //数字
                Pocker pocker = new Pocker(suit,j);

                pockerList.add(pocker); //存
            }
        }
        return pockerList;
    }

    //洗牌

    //换牌
    public static void swap(List<Pocker> pockerList, int i, int j){
        Pocker tmp = pockerList.get(i);
        pockerList.set(i,pockerList.get(j));
        pockerList.set(j,tmp);
    }

    public static void shuffle (List<Pocker> pockerList){
        Random random = new Random();   //产生随机数

        for (int i = pockerList.size() - 1; i>0; i--){
            int index = random.nextInt(i); //生成 0~i-1 随机数
            swap(pockerList,i,index);
        }
     }

     //揭牌 3个人5张牌
    //3个人
    List<Pocker> hand1 = new ArrayList();
    List<Pocker> hand2 = new ArrayList();
    List<Pocker> hand3 = new ArrayList();

    //,用个二维数组来存 牌
    List<List<Pocker>> hand =  new ArrayList<>();
    hand.add(hand1);
    hand.add(hand2);
    hand.add(hand3);

    public static void main(String[] args) {
        List<Pocker> pockerList = buyPocks();
        System.out.println(pockerList);
        shuffle(pockerList);
        System.out.println(pockerList);

    }



}
